package org.ahuanlien.crm.service.impl;

import org.ahuanlien.crm.domain.Company;
import org.ahuanlien.crm.mapper.CompanyMapper;
import org.ahuanlien.crm.query.CompanyQueryObject;
import org.ahuanlien.crm.service.ICompanyService;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
@Service
public class CompanyServiceImpl implements ICompanyService{
    @Autowired
    CompanyMapper companyMapper;

    public int deleteByPrimaryKey(Long id) {
        return companyMapper.deleteByPrimaryKey(id);
    }

    public int insert(Company record) {
        return companyMapper.insert(record);
    }

    public Company selectByPrimaryKey(Long id) {
        return companyMapper.selectByPrimaryKey(id);
    }

    public List<Company> selectAll() {
        return companyMapper.selectAll();
    }

    public int updateByPrimaryKey(Company record) {
        return companyMapper.updateByPrimaryKey(record);
    }

    public void changeState(Long id) {
        companyMapper.changeState(id);
    }

    public PageResult query(CompanyQueryObject qo) {
        int count = companyMapper.queryForCount();
        List<Company> list = companyMapper.queryForList(qo);
        if(count== 0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        return new PageResult(count,list);
    }
}
